<?php


namespace app\agent\controller\user;

use app\agent\controller\Controller;
use app\agent\model\user\AgentUser;

class User extends Controller
{
    /**
     * 代言人列表
     * @return mixed
     * @throws \think\exception\DbException
     */
    public function index()
    {
        $model = new AgentUser;
        $list = $model->getList();
        return $this->fetch('index', ['list' => $list]);
    }

    /**
     * 添加代言人
     * @return mixed
     */
    public function add()
    {
        $model = new AgentUser;
        if ($this->request->isAjax()) {
            $data = $this->postData('agentuser');

            // 新增记录
            $model->add($data);
            return $this->renderSuccess('添加成功', url('user.user/index'));

            return $this->renderError($model->getError() ?: '添加失败');
        } else {
            return $this->fetch('add');
        }

    }


}